package pres.lnk.jxlss;

import java.net.URL;

/**
 *
 * @Author lnk
 * @Date 2018/1/24
 */
public class JxlsConfig {
    /** 模板存放目录 */
    private static String templateRoot;
    /** 默认图片目录 */
    private static String imageRoot;
    /** 锁住配置 */
    private static boolean lock = false;

    static{
        String templateRoot = "";
        URL resource = Thread.currentThread().getContextClassLoader().getResource("jxls_templates");
        if(resource != null){
            templateRoot = resource.getPath();
        }
        JxlsConfig.config()
                //锁住配置，不能再修改
//                .lock()
                //设置模板文件根目录
                .templateRoot(templateRoot)
                //设置图片路径根目录
                .imageRoot("");
    }

    private JxlsConfig(){ }

    private static JxlsConfig config(){
        if(lock){
            throw new IllegalArgumentException("jxls配置已设置锁住，不能再修改");
        }
        return new JxlsConfig();
    }

    public JxlsConfig templateRoot(String templateRoot) {
        JxlsConfig.templateRoot = templateRoot;
        return this;
    }

    public JxlsConfig imageRoot(String imageRoot) {
        JxlsConfig.imageRoot = imageRoot;
        return this;
    }

    public JxlsConfig lock() {
        JxlsConfig.lock = true;
        return this;
    }


    public static String getTemplateRoot() {
        return templateRoot;
    }

    public static String getImageRoot() {
        return imageRoot;
    }
}
